11/27/2022

Normal distributions

Simulate some data

We can simulate data from a normal distribution as follows:

set.seed(144)
x1 <- rnorm(n= 1000, 0, 1)
x2 <- rnorm(n=1000, 3, 4)

data <- as.data.frame(cbind(x1, x2))
head(data)
##           x1         x2
## 1 -1.6505562  1.2206718
## 2  0.6028106 10.0211403
## 3 -0.4738839  0.9871657
## 4 -1.7976130 -0.6453392
## 5 -1.4211210  3.8133647
## 6  0.1588875  6.1606392

Multivariate normal

You could also sample form a multivariate normal distributions, but we won’t do that here.

require(MASS)
Sigma <- matrix(c(7,5,5,9),2,2)
data_mv <- as.data.frame(mvrnorm(n = 1000, rep(0, 2), Sigma))

An interactive table

require(DT, warn.conflicts = F)
datatable(data, options = list(pageLength = 5))

Pivot data

require(reshape, warn.conflicts = F)
data <- melt(data)
datatable(data, options = list(pageLength = 5))

A not so still figure

I have two things to show here

The distribution of \(X_1\): \[X_1 \sim \mathcal{N}(0, 1).\]

The distribution of \(X_2\): \[X_2 \sim \mathcal{N}(3, 4).\]

So two beautiful normal distributions.

Equation time

This doesn’t relate to the normal density stuff at all. But I need to put something here as well. So, just so you know, we can take the inverse of functions:

\[ \begin{align} g_i(\mu_{ij}) &= \nu_{i} + \lambda_i \eta_j \\ \mu_{ij} &= g_i^{-1}(\nu_{i} + \lambda_i \eta_j). \end{align} \]

These relate to the Generalized Linear Factor Analysis (GLFA) Framework. Moderated Nonlinear Factor Analysis can be seen as an extension of this GLFA (Bauer and Hussong 2009).

References

Bauer, D. J., and A. M. Hussong. 2009. “Psychometric Approaches for Developing Commensurate Measures Across Independent Studies Traditional and New Models.” Psychological Methods 14 (2): 101.